package com.person.ntv.service.sys.impl;

import java.math.BigDecimal;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.person.common.PageParams;
import com.person.exception.ServiceException;
import com.person.ntv.dao.sys.SysFileMapper;
import com.person.ntv.entity.sys.SysFile;
import com.person.ntv.service.base.impl.BaseServiceImpl;
import com.person.ntv.service.sys.SysFileService;

/**
 * @Title: SysFileServiceImpl
 * @Description: 
 * @author lqy
 * @date 2016年11月16日
 * @version V1.0
 */
@Service("sysFileService")
public class SysFileServiceImpl extends BaseServiceImpl<SysFile>implements SysFileService {
	@Autowired
	private SysFileMapper sysFileMapper;
	 @Autowired
	public void setBaseMapper(){
		   super.setBaseMapper(this.sysFileMapper);
	 }
	
	@Override
	public Page<SysFile> getFilePage(PageParams params) throws ServiceException {
		try{
			PageHelper.startPage(params.getPage(),params.getRows(),params.getOrderStr(null));
			return sysFileMapper.selectPage(params.getParams());
			}catch (Exception e) {
		          e.printStackTrace();
		          throw new ServiceException("系统错误。");
		  } 
	}
	@Override
	public int delFilesByIds(BigDecimal[] ids) throws ServiceException {
		try{
			//先删除物理文件
			List<SysFile>files =selectByIds(StringUtils.join(ids,','));
			for(SysFile file:files){
				//删除
				file.getNewName();
			}
			return deleteByIds(StringUtils.join(ids,','));
			}catch (Exception e) {
		          e.printStackTrace();
		          throw new ServiceException("系统错误。");
		  }
	}
	@Override
	public int delFilesByFUUID(String uuid) throws ServiceException {
		try{
			//先删除物理文件
			SysFile sysFile=new SysFile();
			sysFile.setForeignUuid(uuid);
			List<SysFile>files =select(sysFile);
			for(SysFile file:files){
				//删除
				file.getNewName();
			}
			return  delete(sysFile);
			}catch (Exception e) {
		          e.printStackTrace();
		          throw new ServiceException("系统错误。");
		  } 
	}
	@Override
	public List<SysFile> selectFilesByFUUID(String uuid)throws ServiceException {
		try{
			SysFile sysFile=new SysFile();
			sysFile.setForeignUuid(uuid);
			return  select(sysFile);
			}catch (Exception e) {
		          e.printStackTrace();
		          throw new ServiceException("系统错误。");
		  }
	}
   
}
